package com.xiaouyudeguang.common.serializer;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.xiaouyudeguang.common.utils.EncryptUtils;
import com.xiaouyudeguang.common.utils.StringUtils;

import java.io.IOException;

/**
 * 解密
 */
public class DecryptJsonSerializer extends JsonSerializer<String> {

    @Override
    public void serialize(String data, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
        jsonGenerator.writeString(StringUtils.isBlank(data) ? null : EncryptUtils.decrypt(data));
    }
}